<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>绝对定位使用场景_居中</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        div{
            width: 400px;
            height: 100px;
            background: pink;
            margin: 100px auto;
            position: relative;
        }
        div p{
            width: 100px;
            height: 100px;
            background: gold;
            margin-left: -50px;
            position: absolute;
            left: 50%;
        }
    </style>
</head>
<body>
    <div>
        <p></p>
    </div>
</body>
</html>